package net.huafv.authoritycontrol.security;


import net.huafv.authoritycontrol.admin.entity.SysUser;
import net.huafv.authoritycontrol.admin.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;


@Service
public class UserDetailServiceImpl implements UserDetailsService {

	@Autowired
	SysUserService sysUserService;

	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

		SysUser sysUser = sysUserService.getByUsername(username);

		System.out.println(sysUser);

		if (sysUser == null) {
			throw new UsernameNotFoundException("用户名或密码不正确");
		}

		return new AccountUser(sysUser.getId(), sysUser.getUsername(), sysUser.getPassword(), null);
	}

}
